package com.ice.day726.thread;

import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

class Solution1 {

    /* Write Code Here */
    public int findMinDifference(String[] timePoints) {
        Date[] dates = new Date[timePoints.length];
        for(int i=0;i<timePoints.length;i++) {
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm");
            Date date =null;
            try {
                date = simpleDateFormat.parse(timePoints[i]);
                dates[i] = date;
            } catch (ParseException e) {
                e.printStackTrace();
            }

        }
        Arrays.sort(dates);
        long [] differences = new long[dates.length];
        for(int i = 0; i< dates.length; i++){
            if(dates.length-1==i){
                differences[i] = Math.abs((dates[i].getTime()- dates[0].getTime())/60000L);
            }else{
                differences[i] = Math.abs((dates[i+1].getTime()- dates[i].getTime())/60000L);
            }
            if(differences[i]>720L){
                differences[i] = 1440L-differences[i];
            }

        }
        Arrays.sort(differences);
//        System.out.println(Arrays.toString(differences));
        long min = differences[0];
        return Integer.parseInt(Long.toString(min));
    }
}
/**
* @author ice2020x
* @Date: 2022/8/7
* @Description:
 *
 * 给定一个 24 小时制（小时:分钟 "HH:MM"）的时间列表，找出列表中任意两个时间的最小时间差并以分钟数表示。
**/
public class Main4 {
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        int res;

        int timePoints_size = 0;
        timePoints_size = in.nextInt();
        if (in.hasNextLine())
            in.nextLine();
        String[] timePoints = new String[timePoints_size];
        String timePoints_item;
        for(int timePoints_i = 0; timePoints_i < timePoints_size; timePoints_i++) {
            try {
                timePoints_item = in.nextLine();
            } catch (Exception e) {
                timePoints_item = null;
            }
            timePoints[timePoints_i] = timePoints_item;
        }

//        res = new Solution().findMinDifference(timePoints);
//        System.out.println(String.valueOf(res));
    }
}